<template>
	<page-loading :show='pageLoading'>
		<view class="box">
    <u-navbar title="我的收益" :border-bottom="false"></u-navbar>
    <view class="header">
      <view class="look">
        <text @click="gotoMx">查看明细</text>
      </view>
      <view class="content">
        <view class="flex flex-jc-c" style="margin-top: 100rpx;">
          <view class="img">
						<i-icon icon='iconyue' size='100rpx' color='rgb(253,217,45)'></i-icon>
					</view>
        </view>
        <view class="price" style="margin-top: 60rpx;">
          <view>余额（元）</view>
          <view class="momeny">{{info.balance}}</view>
        </view>
        <view class="flex flex-jc-c" style="margin-top: 100rpx;" @tap="$u.debounce(withdrawal, 500)">
          <view class="btn">提现</view>
        </view>
        <view class="flex flex-jc-sa botton">
          <view>
            <view class="num">{{info.profit}}</view>
            <view class="text">累计收益（元）</view>
          </view>
          <view>
            <view class="num">{{info.count}}</view>
            <view class="text">累计订单</view>
          </view>
          <view>
            <view class="num">{{info.waitProfitCount}}</view>
            <view class="text">可得收益（元）</view>
          </view>
        </view>
      </view>
    </view>
    <view class="footer flex flex-jc-sb" @click="goPage">
      <view>新手指引</view>
      <view>
        <u-icon name="arrow-right" color="#999999"></u-icon>
      </view>
    </view>
  
		<u-toast ref="uToast" />
	</view>
</page-loading>
</template>

<script>
	import baseUrl from '@/utils/baseUrl.js' // api接口地址
  export default {
    data() {
      return {
				pageLoading:false,
        info: [],
				isRz:2, //是否实名认证
				userInfo:{
					contractNo:2,
					bindPhone:2,
					audit:2,
					authentication:2
				},
				phone:'',
				userId:'',
				idCardNum:0,
				baseUrl:'https://testapi.yzsheng.com'
      }
    },
		onLoad() {
			
		},
    created() {
			this.phone = uni.getStorageSync('Ztc_C_USER_INFO').mobile
			this.userId = uni.getStorageSync('Ztc_C_USER_INFO').id
			if (baseUrl === 'https://testapi.yzsheng.com') {
			  this.baseUrl = `/pages_fundModule/authorization/authorization?type=1&userId=${this.userId}&phone=${this.phone}&link=https://clientv2.yzsheng.com/test/tonglian.html`
			} else if (baseUrl === 'https://lineapi.yzsheng.com') {
				this.baseUrl = `/pages_fundModule/authorization/authorization?type=1&userId=${this.userId}&phone=${this.phone}&link=https://ztch5.yzsheng.com/cilentH5/pay/tonglian.html`
			}
    },
		onShow() {
			// console.log(uni.getStorageSync('Ztc_C_USER_INFO'))
			// this.isCard()
			this.getUserMoneyInfo()
			this.getCertificationProgress()
			this.getBankcardList()
			// this.pageUrl()
		},
    methods: {
			//是否绑定手机同意协议等等云商通用户id
			async getCertificationProgress(){
				try {
					let data = {
						'type': 0
					}
				  const res = await this.$api.fundModule.getCertificationProgress(data)
				  this.userInfo = res.data
					this.pageLoading = true
				} catch (e) {
				  //TODO handle the exception
				}
			},
			//是否认证
			async isCard() {
			  try {
			    const res = await this.$api.me.checkIDCardVerify()
			    this.isRz = res.data
			  } catch (e) {
			    //TODO handle the exception
			  }
			},
			//跳转同意协议
			async pageUrl() {
				try{
					const res = await this.$api.fundModule.signContract()
					uni.navigateTo({
					  url: '/pages_fundModule/authorization/authorization?link=' + encodeURIComponent(res
					    .data.uRl)+'&type=0'
					})
				}catch(e){
					//TODO handle the exception
				}
			},
      //是否有银行卡
			async getBankcardList(){
				try {
					let data = {
						"pageIndex": 1,
						"pageSize": 5
					}
				  const res = await this.$api.fundModule.getBankcardList(data)
				  this.idCardNum = res.data.list.length
				} catch (e) {
				  //TODO handle the exception
				}
			},
			withdrawal() {
				if(this.userInfo.contractNo===2||this.userInfo.bindPhone===2||this.userInfo.authentication===2)return false
				if(!this.userInfo.authentication){
					this.$refs.uToast.show({
					  title: '请实名认证',
					  url: '/pages_commodity/idCarsAuthentication/idCarsAuthentication?typeid=withdrawal'
					})
				}else if(!this.userInfo.contractNo){//没有同意协议
					this.pageUrl()
				}else if(!this.userInfo.bindPhone){ //没有绑定手机号
					uni.navigateTo({
						url:encodeURI(this.baseUrl)
					})
				}else if(this.idCardNum===0){ //没有绑定银行卡
					uni.navigateTo({
						url:'/pages_fundModule/addBankCard/addBankCard'
					})
				}else{
        	uni.navigateTo({
        	  url: '/pages_fundModule/withdrawal/withdrawal' //添加银行卡
        	  // url: '/pages_fundModule/withdrawal/withdrawal' 提现
        	})
        }
        
      },
      goPage(url) {
        uni.navigateTo({
          url: '/pages_common/pages_me/strategy/strategy'
        })
      },

      gotoMx() {
        uni.navigateTo({
          url: '/pages_userModule/incomeExpenditur/incomeExpenditur'
        })
      },
      async getUserMoneyInfo() {
        try {
          let data = {

          }
          const res = await this.$api.me.getUserMoneyInfo(data)
          // console.log(res)
          this.info = res.data
        } catch (e) {
          console.log(e)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .box {
		min-height: 100vh;
    background-color: #EEEEEE;
  }

  .header {
    padding: 0 33rpx 0 33rpx;
    background-color: #fff;
    margin-top: 15rpx;

    //查看明细
    .look {
      font-size: 26rpx;
      font-weight: 500;
      color: #333333;
      padding-top: 41rpx;
      display: flex;
      justify-content: flex-end;
    }

    //余额内容
    .content {
      text-align: center;

      .img {
        width: 106rpx;
        height: 93rpx;
        line-height: 93rpx;
        // background: linear-gradient(0deg, #FBD220, #FFE23E);
      }

      .price {
        font-size: 28rpx;
        font-weight: 500;
        color: #656565;

        .momeny {
          font-size: 72rpx;
          font-weight: bold;
          color: #363636;
        }
      }

      .btn {
        line-height: 88rpx;
        font-size: 30rpx;
        font-weight: 500;
        color: #3D3D3D;
        width: 468rpx;
        height: 88rpx;
        background: linear-gradient(0deg, #FBD220, #FFE23E);
        border-radius: 44rpx;

      }

      .botton {
        margin-top: 80rpx;
        padding-top: 40rpx;
        border-top: 2rpx solid #EEEEEE;
        padding-bottom: 50rpx;

        .num {
          font-size: 42rpx;
          color: #363636;
          font-weight: bold;
        }

        .text {
          color: #999999;
          font-size: 26rpx;
        }

      }
    }

  }

  //尾部
  .footer {
    height: 96rpx;
    background: #FFFFFF;
    padding: 33rpx 33rpx 0 33rpx;
    margin-top: 20rpx;
  }
</style>
